<?php

namespace app\admin\service;

use app\admin\model\AccessModel;
use app\admin\model\AdminModel;

class AccessService extends BaseService
{
    /**
     * 获取角色下的所有权限
     *
     * @Author tanruizheng
     * @DateTime 2021-07-12
     * @param [type] $roleId
     * @return array
     */
    public static function getAccessList($roleId){
        if(AdminModel::SUPER_ADMIN_ROLE_ID == $roleId){
            $accessList = [
                [
                    'app' => '%',
                    'controller' => '%',
                    'action' => '%'
                ]
            ];
        }else{
            $roleIds = RoleService::getChildrenRoleIdList($roleId,true);
            $accessList = AccessModel::where('role_id','IN',$roleIds)->field('app,controller,action')->select()->toArray();
        }
        return $accessList;
    }
}